﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using WordDocumentGenerator.Library;

namespace GPS.ENTITYS
{
    public class CrudModelDCPDVGTVT
    {
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:0}")]
        public decimal? STT { get; set; }
        public string ExportWord { get; set; }
        public string DVGTVT_MA { get; set; }
        public string DVGTVT_MAQL { get; set; }
        public string DVGTVT_TEN { get; set; }
        public string DVGTVT_TEL { get; set; }
        public string DVGTVT_FAX { get; set; }
        public string DVGTVT_ADD { get; set; }
        public string DVGTVT_HANGGPLX { get; set; }
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:0}")]
        public decimal? DVGTVT_LLDT { get; set; }
        public string DVGTVT_LOAI { get; set; }
        public string DVGTVT_SOGP { get; set; }
        [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
        public DateTime? DVGTVT_NGAYGP { get; set; }
        [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
        public DateTime? DVGTVT_NGAYHHGP { get; set; }
        public string DVGTVT_ACTIVE { get; set; }
        public string DCP_DVGTVT_MA { get; set; }
        public string DCP_DVGTVT_MAQL { get; set; }
        public string DCP_DVGTVT_TEN { get; set; }
        public string DCP_DVGTVT_TEL { get; set; }
        public string DCP_DVGTVT_FAX { get; set; }
        public string DCP_DVGTVT_ADD { get; set; }
        public string DCP_DVGTVT_HANGGPLX { get; set; }
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:0}")]
        public decimal? DCP_DVGTVT_LLDT_CU { get; set; }
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:0}")]
        public decimal? DCP_DVGTVT_LLDT_MOI { get; set; }
        public string DCP_DVGTVT_LOAI { get; set; }
        public string DCP_SOGP_CU { get; set; }
        [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
        public DateTime? DCP_NGAYGP_CU { get; set; }
        [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
        public DateTime? DCP_NGAYHHGP_CU { get; set; }
        public string DCP_SOVB_KT { get; set; }
        [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
        public DateTime? DCP_NGAYVB_KT { get; set; }
        public string DCP_SOVB_TT { get; set; }
        public DateTime? DCP_NGAYVB_TT { get; set; }
        public string DCP_SOGP_MOI { get; set; }
        [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
        public DateTime? DCP_NGAYGP_MOI { get; set; }
        [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
        public DateTime? DCP_NGAYHHGP_MOI { get; set; }
        public string DCP_MOTA { get; set; }
        public string DCP_STATUS { get; set; }
        [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
        public DateTime? DCP_NGAYNHAP { get; set; }
        public string DCP_NGUOINHAP { get; set; }
    }

    public class EXPORTWORD_DCPDVGTVT
    {
        public static byte[] EXPORT_DCPDVGTVT(string templateFileName, object objSource, string docType)
        {
            DocumentGenerationInfo generationInfo = GetDocumentGenerationInfo(docType, "1.0", objSource, templateFileName, false);
            COMMON.ExportCore<CrudModelDCPDVGTVT> docGenerator = new COMMON.ExportCore<CrudModelDCPDVGTVT>(generationInfo);
            return docGenerator.GenerateDocument();
        }
        /// <summary>
        /// Gets the document generation info.
        /// </summary>
        /// <param name="docType">Type of the doc.</param>
        /// <param name="docVersion">The doc version.</param>
        /// <param name="dataContext">The data context.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="useDataBoundControls">if set to <c>true</c> [use data bound controls].</param>
        /// <returns></returns>
        private static DocumentGenerationInfo GetDocumentGenerationInfo(string docType, string docVersion, object dataContext, string fileName, bool useDataBoundControls)
        {
            DocumentGenerationInfo generationInfo = new DocumentGenerationInfo();
            generationInfo.Metadata = new DocumentMetadata
            {
                DocumentType = docType,
                DocumentVersion = docVersion
            };
            generationInfo.DataContext = dataContext;
            generationInfo.TemplateData = File.ReadAllBytes(fileName);
            generationInfo.IsDataBoundControls = useDataBoundControls;
            return generationInfo;
        }

    }
}
